package lhc.alg.top100;

/**
 * description: https://leetcode.cn/problems/merge-sorted-array/
 *  88 合并两个有序数组  双指针
 * author: hongchen.liao
 * date:  2022/10/8
 */
public class _88_ {

    class Solution {
        public void merge(int[] nums1, int m, int[] nums2, int n) {
            int[] ans = new int[m+n];
            int p1 = 0, p2 = 0;
            int curr = 0;
            while(p1 < m || p2 < n){
                if(p1 == m){
                    curr = nums2[p2++];
                }else if(p2 == n){
                    curr = nums1[p1++];
                }else if(nums1[p1] < nums2[p2]){
                    curr = nums1[p1++];
                }else{
                    curr = nums2[p2++];
                }
                ans[p1+p2-1] = curr;
            }
            for(int i = 0; i < m+n; i++){
                nums1[i] = ans[i];
            }
        }
    }

}
